package sk.stuba.fiit.clientApp.gui.model;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;
import sk.stuba.fiit.clientApp.cvo.FileDetailCVO;

/**
 * Trieda zodpovedná za držanie modelu tabuľky súborov, ktoré budú podpísané
 * @author Administrator
 *
 */
public class FileTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final int colum = 4;
	private Vector<FileDetailCVO> files;

	public FileTableModel(Vector<FileDetailCVO> files) {
		this.files = files;
	}
	
	public FileTableModel() {
		this.files = new Vector<FileDetailCVO>();
	}

	private String hlavicka[] = { "Name", "Extension", "Size", "Path" };

	@Override
	public String getColumnName(int column) {
		return hlavicka[column];
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		switch (columnIndex) {
		case 0:
			return String.class;
		case 1:
			return String.class;
		case 2:
			return Long.class;
		case 3:
			return String.class;
		}
		return null;
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}

	public int getColumnCount() {
		return colum;
	}

	public int getRowCount() {
		return files.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		FileDetailCVO file = (FileDetailCVO) files.get(rowIndex);
		
		switch (columnIndex) {
		case 0:	return file.getName() ;
		case 1:	return file.getExtension();
		case 2: return file.getSize();
		case 3: return file.getPath();
		}

		return null;
	}

	@Override
	public void setValueAt(Object value, int rowIndex, int columnIndex) {
		FileDetailCVO file = (FileDetailCVO) files.get(rowIndex);
		switch (columnIndex) {
		case 1:
			file.setName((String) value);
			break;
		case 2:
			file.setExtension((String) value);
			break;
		case 3:
			file.setSize((Long)value);
			break;
		case 4:
			file.setPath((String) value);
			break;

		}
	}
	
	public void addFiles(FileDetailCVO detailCVO){
		files.add(detailCVO);
		super.fireTableDataChanged();		
	}

	public void removeFiles(int position){
		files.remove(position);
		super.fireTableDataChanged();
	}
	
	public void makeEmptyModel(){
		this.files = new Vector<FileDetailCVO>();
		super.fireTableDataChanged();
	}
}
